Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@janiscommerce/model
Advanced tools
[![Build Status](https://travis-ci.org/janis-commerce/model.svg?branch=master)](https://travis-ci.org/janis-commerce/model) [![Coverage Status](https://coveralls.io/repos/github/janis-commerce/model/badge.svg?branch=master)](https://coveralls.io/github/ja
npm install @janiscommerce/model
The client injection is useful when you have a dedicated database per client.
Using the public setter client
, the client will be stored in the controller
instance.
All the controllers and models getted using that controller will have the client injected.
The Model
uses Database Dispatcher for getting the correct DBDriver for a Model
.
The DBDriver will perform all the queries to the database.
If you have the connection settings you should add a databaseKey
getter in you Model
.
class MyModel extends Model {
get databaseKey() {
return 'core';
}
}
Database Dispatcher will try to use one of the following settings
/path/to/root/.janiscommercerc.json
:{
"database": {
"core": {
"host": "http://my-host-name.org",
"type": "mysql",
// ...
}
}
}
DB_CORE_HOST = "http://my-host-name.org";
DB_CORE_DATABASE = "db-name";
DB_CORE_USER = "user";
DB_CORE_PASSWORD = "foo123456";
When your Model
is a Client Model, and the database connection settings are in the client injected, you don't need to configurate the databaseKey
.
You can add settings for the fields in the connection, the fields are the following.
For settings the package use Settings.
Field | Default value | Description |
---|---|---|
clients.fields.read.type | dbReadType | The type for DB Read (mylsq, mongodb) |
clients.fields.read.host | dbReadHost | The host for DB Read |
clients.fields.read.protocol | dbReadProtocol | The database protocol for DB Read |
clients.fields.read.database | dbReadDatabase | The database name for DB Read |
clients.fields.read.user | dbReadUser | The database username for DB Read |
clients.fields.read.password | dbReadPassword | The database password for DB Read |
clients.fields.read.port | dbReadPort | The database port for DB Read |
clients.fields.write.type | dbWriteType | The type for DB Write (mylsq, mongodb) |
clients.fields.write.host | dbWriteHost | The host for DB Write |
clients.fields.write.protocol | dbWriteProtocol | The database protocol for DB Write |
clients.fields.write.database | dbWriteDatabase | The database name for DB Write |
clients.fields.write.user | dbWriteUser | The database username for DB Write |
clients.fields.write.password | dbWritePassword | The database password for DB Write |
clients.fields.write.port | dbWritePort | The database port for DB Write |
Example of settings:
// .janiscommercerc.json
{
"clients": {
"fields": {
"read": {
"type": "dbReadType",
"host": "dbReadHost",
"protocol": "dbReadProtocol",
"database": "dbReadDatabase",
"user": "dbReadUser",
"password": "dbReadPassword",
"port": "dbReadPort"
},
"write": {
"type": "dbWriteType",
"host": "dbWriteHost",
"protocol": "dbWriteProtocol",
"database": "dbWriteDatabase",
"user": "dbWriteUser",
"password": "dbWritePassword",
"port": "dbWritePort"
}
}
}
}
const items = await myModel.get({ filters: { status: 'active' } });
await myModel.getPaged({ filters: { status: 'active' } }, (items, page, limit) => {
// items is an array with the result from DB
});
get()
sometimes you need data of totals. This method returns an object with that information.
Result object structure:
pages: The total pages for the filters applied
page: The current page
limit: The limit applied in get
total: The total number of items in DB for the applied filters
await myModel.get({ filters: { status: 'active' } });
const totals = await myModel.getTotals();
/**
totals content:
{
pages: 3,
page: 1,
limit: 500,
total: 1450
}
*/
await myModel.insert({ foo: 'bar' });
const items = await myModel.get({ filters: { foo: 'bar' }});
/**
itemInserted content:
[
{
foo: 'bar'
}
//...
]
*/
await myModel.save({ foo: 'bar' });
const items = await myModel.get({ filters: { foo: 'bar' }});
/**
items content:
[
{
foo: 'bar'
}
//...
]
*/
filter
.await myModel.update({ updated: 1 }, { status: 5 });
// will set updated = 1 for the items that has status = 5
await myModel.remove({ foo: 'bar' });
const items = await myModel.get({ filters: { foo: 'bar' }});
/**
items content:
[]
*/
await myModel.multiInsert([{ foo: 1 }, { foo: 2 }]);
const items = await myModel.get();
/**
items content:
[
{ foo: 1 },
{ foo: 2 }
]
*/
await myModel.multiSave([{ foo: 1 }, { foo: 2 }]);
const items = await myModel.get();
/**
items content:
[
{ foo: 1 },
{ foo: 2 }
]
*/
await myModel.multiRemove({ status: 2 });
const items = await myModel.get({ filters: { status: 2 }});
/**
items content:
[]
*/
FAQs
A package for managing Janis Models
We found that @janiscommerce/model demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.